

Dim doc
Set doc = application.ActiveDocument
GetUserLicence(doc)
doc.currentunit = 2
dim ObjFSO
main
sub main()
	dim selObj
	selObj = ""
	dim cmps,cmp
	set cmps = doc.components(1)
	for each cmp in cmps
		selObj = selObj & cmp.name & " "
	next
 
	call SetClipboardText_fm20(selobj)
	msgbox "done"
end sub


'#################################################################
'#################################################################
'#################################################################
'#################################################################
' Function to validate document
Private Function ValidateServer(docObj)
    Dim key, licenseServer, licenseToken
    key = docObj.Validate(0)
    Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Application")
    licenseToken = licenseServer.GetToken(key)
    Set licenseServer = nothing
    'On Error Resume Next
    Err.Clear
    docObj.Validate(licenseToken)
    If Err Then
        ValidateServer = 0    
    Else 
        ValidateServer = 1
    End If
End Function

sub GetUserLicence(docObj)

	If ValidateServer(docObj) = 0 Then
	    msgbox "Server validation failed."
	    exit sub
	End If
	
end sub


''' copy and paste
Function SetClipboardText_fm20(oText)   '剪切读取板信息
    Dim Form, TextBox
	Set Form = CreateObject("Forms.Form.1") 
	Set TextBox = Form.Controls.Add("Forms.TextBox.1").Object 
	TextBox.MultiLine = True 
	TextBox.Text = oText
	TextBox.SelStart = 0 
	TextBox.SelLength = TextBox.TextLength 
	TextBox.Copy
End Function

Function GetClipboardText_fm20()   '剪切读取板信息
    Dim Form, TextBox
	Set Form = CreateObject("Forms.Form.1")
	Set TextBox = Form.Controls.Add("Forms.TextBox.1").Object
	TextBox.MultiLine = True
	If TextBox.CanPaste Then
		 TextBox.Paste
		 args = TextBox.Text
	End If	
	GetClipboardText_fm20 = args
End Function

Sub SetClipboardText(oText)   '写入信息到剪切板
DIM wsShell
    Set wsShell = CreateObject("WScript.Shell")
    wsShell.Run "mshta vbscript:ClipboardData.SetData("&chr(34)&"text"&chr(34)&"," &Chr(34)& oText &Chr(34)& ")(close)",0,True
End Sub

Function GetClipboardText()   '剪切读取板信息
    Set objHTML=CreateObject("htmlfile") 'xmlfile、mhtmlfile也可以
    GetClipboardText = objHTML.Pare
end function